//pragma javascript
function ScriptBlockhelp(sender, args) {
	if (args.length === 0) {
		helpStr = ['§7------ ScriptBlock Help ------§a'];
		for (i = 0;i<CommandList.length; i++){
			helpStr.push("§2/"+CommandList[i][0]+ ":§f " +CommandList[i][1]);
		}
		return sender.sendMessage(helpStr.join("\n"));
	}
	if (!sender.isPlayer()) {
		switch (args[0]) {
		case 'cmd':
			sblock_cmd(args);
		break;
		case 'exec':
			if (args.length != 6) return logger.warning(lang.err.arg);
			if (blockData[args[2]] === undefined) return logger.warning(lang.tips.non_existent_sblock);
			pos = [args[3], args[4], args[5]].join("_");
			getblockData = blockData[args[2]][pos];
			if (getblockData === undefined) return logger.warning(lang.tips.non_sblock);
			playerList = args[1] === "@a" ? server.getInstance().getOnlinePlayers().values().toArray() : [server.getPlayer(args[1])];
			for (i = 0; i < playerList.length; i++) {
				if (playerList[i] === null) return logger.warning(lang.warn.non_online);
				ScriptBlockCore(getblockData, server.getPlayer(playerList[i]), pos);
			}
		break;
		default:
			logger.warning(lang.warn.is_console);
		}
		return;
	}
	if (!(sender.isOp()&&sender.isPlayer())) return sender.sendMessage(lang.warn.no_rights);
	name = sender.getPlayer().name;
	switch (args[0]) {
	case 'cmd':
		sblock_cmd(args);
		break;
	case 'add':
		sender.sendMessage(lang.tips.start_click);
		playObj[name] = {};
		playObj[name].addBlockClick = true;
		break;
	case 'set':
		sender.sendMessage(lang.tips.start_click);
		playObj[name] = {};
		playObj[name].setBlockClick = true;
		break;
	case 'delete':
		if (args.length != 5) return logger.warning(lang.err.arg);
		delete blockData[args[1]][[args[2], args[3], args[4]].join("_")];
		manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json", JSON.stringify(blockData));
		sender.sendMessage('已删除');
		break;
	case 'move':
		sender.sendMessage(lang.tips.start_click);
		playObj[name] = {};
		playObj[name].moveBlockClick = true;
		break;
	case 'list':
		blockList = '';
		if(args.length === 1) {
			for (keyName in blockData) {
				blockList += keyName + '\n';
				for(posName in blockData[keyName]) {
					blockList += '   '+posName.replace(/_/g, ' ')+'\n';
				}
			}
		} else if(blockData[args[1]]) {
			blockList += args[1] + '\n';
			for(posName in blockData[args[1]]) {
				blockList += '   '+posName.replace(/_/g, ' ')+'\n';
			}
		}
		sender.sendMessage(blockList)
		break;
	case 'reload':
		blockData = JSON.parse(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json")),
		Config = JSON.parse(manager.YAMLtoJSON(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/Config.yml"))),
		lang = JSON.parse(manager.YAMLtoJSON(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/lang/"+Config.language+".yml"))),
		playObj = {};
		sender.sendMessage(lang.tips.reload_done);
		break;
	default:
		sender.sendMessage(lang.tips.non_cmd);
	}
}
function sblock_cmd(args){
	if (args[1] === 'tp') {
		playerList = args[2] === "@a" ? server.getInstance().getOnlinePlayers().values().toArray() : [server.getPlayer(args[2])];
		for (i = 0; i < playerList.length; i++) {
			if (playerList[i] === null) return logger.warning(lang.warn.non_online);
			world.loadLevel(args[3]);
			let worldObj = server.getLevelByName(args[3]);
			if(worldObj === null) return playerList[i].sendMessage("世界 "+args[3]+" 加载失败。");
			let worldPos = worldObj.getSpawnLocation();
			let PosObj;
			if(args.length > 4) {
				PosObj = Java.type("cn.nukkit.level.Position").fromObject(manager.buildvec3(args[4], args[5], args[6]), server.getLevelByName(args[3]));
			} else {
				PosObj = worldPos;
			}
			playerList[i].teleport(PosObj);
		}
		//server.getLevelByName(名字).getSpawnLocation;
	} else if (args[1] === 'tell') {
		playerList = args[2] === "@a" ? server.getInstance().getOnlinePlayers().values().toArray() : [server.getPlayer(args[2])];
		for (i = 0; i < playerList.length; i++) {
			if (playerList[i] === null) return logger.warning(lang.warn.non_online);
			playerList[i].sendMessage(args[3]);
		}
	} else if (args[1] === 'clear') {
		playerList = args[2] === "@a" ? server.getInstance().getOnlinePlayers().values().toArray() : [server.getPlayer(args[2])];
		for (i = 0; i < playerList.length; i++) {
			if (playerList[i] === null) return logger.warning(lang.warn.non_online);
			blockitem.removeItemToPlayer(playerList[i], blockitem.buildItem(args[3], args[4], args[5]));
		}
	} else if (args[1] === 'particle') {
		if (args.length != 7) return logger.warning(lang.err.arg);
		posEntity = Java.type("cn.nukkit.level.Position").fromObject(manager.buildvec3(new Number(args[4])+0.5, new Number(args[5])+0.5, new Number(args[6])+0.5), server.getLevelByName(args[3]));
		particle.drawCircle(posEntity, 0.1, new Number(args[2]), 0.1)
	}
}
function addBlockWinCallback(sender) {
	//添加脚本方块窗口回调
	arr = [];
	player = sender.getPlayer();
	name = player.name
	infoBlock = playObj[name].infoBlock;
	input = window.getEventCustomVar(sender, 0, "input");
	input ? arr.push(window.getEventCustomVar(sender, 0, "input")) : arr.push(infoBlock.world);
	for (i = 1; i < 4; i++) {
		input = window.getEventCustomVar(sender, i, "input");
		if (input) {
			arr.push(window.getEventCustomVar(sender, i, "input"));
			continue;
		}
		arr.push(infoBlock.pos[i - 1]);
	}
	triggerType = window.getEventCustomVar(sender, 4, "dropdown");
	isCancell = window.getEventCustomVar(sender, 5, "toggle") == "TRUE" ? true : false;
	ResetTime = new Date(window.getEventCustomVar(sender, 6, "input")).getTime() || new Date().getTime();
	ResetDelay = new Number(window.getEventCustomVar(sender, 7, "input")) || 0;
	TriggerDelay = window.getEventCustomVar(sender, 8, "input") || 0;
	TriggerInterval = window.getEventCustomVar(sender, 9, "input") || 0;
	NumOfTrigger = window.getEventCustomVar(sender, 10, "input") || 0;
	isTips = window.getEventCustomVar(sender, 11, "toggle") == "TRUE" ? true : false;
	Tips = window.getEventCustomVar(sender, 12, "input") || [];
	cmd = window.getEventCustomVar(sender, 13, "input");
	if (cmd === "") return player.sendMessage("§4未输入命令！");
	arr.push(triggerType, cmd);
	if (!blockData[infoBlock.world]) blockData[infoBlock.world] = {};
	blockData[infoBlock.world][infoBlock.pos.join("_")] = {
		type: triggerType,
		isCancell: isCancell,
		ResetPlayerDataTime: ResetTime,
		ResetPlayerDataDelay: ResetDelay,
		ResetPlayerDataDelayTime: (ResetDelay > 0 ? ResetTime + ResetDelay * 60 * 1000 : ResetDelay),
		TriggerDelay: TriggerDelay,
		TriggerInterval: TriggerInterval,
		NumOfTrigger: NumOfTrigger,
		isTips: isTips,
		Tips: Tips,
		cmd: cmd,
		PlayerData: {}
	};
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json", JSON.stringify(blockData));
	player.sendMessage(arr.join(","));
	playObj[name].infoBlock = {};
}
function setBlockWinCallback(sender) {
	//设置脚本方块窗口回调
	player = sender.getPlayer();
	name = player.name;
	triggerType = window.getEventCustomVar(sender, 0, "dropdown");
	isCancell = window.getEventCustomVar(sender, 1, "toggle") == "TRUE" ? true : false;
	ResetTime = new Date(window.getEventCustomVar(sender, 2, "input")).getTime() || new Date().getTime();
	ResetDelay = new Number(window.getEventCustomVar(sender, 3, "input")) || 0;
	TriggerDelay = window.getEventCustomVar(sender, 4, "input") || 0;
	TriggerInterval = window.getEventCustomVar(sender, 5, "input") || 0;
	NumOfTrigger = window.getEventCustomVar(sender, 6, "input") || 0;
	isTips = window.getEventCustomVar(sender, 7, "toggle") == "TRUE" ? true : false;
	Tips = window.getEventCustomVar(sender, 8, "input") || [];
	cmd = window.getEventCustomVar(sender, 9, "input");
	infoBlock = playObj[name].infoBlock;
	if (cmd === "") {
		delete blockData[infoBlock.world][infoBlock.pos.join("_")];
		player.sendMessage(lang.tips.del_sblock);
	} else {
		blockData[infoBlock.world][infoBlock.pos.join("_")] = {
			type: triggerType,
			isCancell: isCancell,
			ResetPlayerDataTime: ResetTime,
			ResetPlayerDataDelay: ResetDelay,
			ResetPlayerDataDelayTime: (ResetDelay > 0 ? ResetTime + ResetDelay * 60 * 1000 : ResetDelay),
			TriggerDelay: TriggerDelay,
			TriggerInterval: TriggerInterval,
			NumOfTrigger: NumOfTrigger,
			isTips: isTips,
			Tips: Tips,
			cmd: cmd,
			PlayerData: {}
		}
		player.sendMessage(lang.tips.new_set);
	}
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json", JSON.stringify(blockData));
	playObj[name].infoBlock = {};
}
function moveBlockWinCallback(sender) {
	//移动脚本方块窗口回调
	arr = [];
	player = sender.getPlayer();
	name = player.name;
	infoBlock = playObj[name].infoBlock;
	input = window.getEventCustomVar(sender, 0, "input");
	let world = input ? window.getEventCustomVar(sender, 0, "input") : infoBlock.world;
	for (i = 1; i < 4; i++) {
		input = window.getEventCustomVar(sender, i, "input");
		if (input) {
			arr.push(window.getEventCustomVar(sender, i, "input"));
			continue;
		}
		arr.push(infoBlock.pos[i - 1]);
	}
	if(world === infoBlock.world && arr.join("_") === infoBlock.pos.join("_")) return player.sendMessage(lang.warn.move_faild);
	(function(data){blockData[world][arr.join("_")] = data})(playObj[name].fromInfoBlock);
	delete blockData[infoBlock.world][infoBlock.pos.join("_")];
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json", JSON.stringify(blockData));
	player.sendMessage(lang.tips.move_suc.replace('%1%', arr.join(" ")));
	playObj[name].infoBlock = {};
	playObj[name].fromInfoBlock = {};
}
function ScriptBlockRTouchCallBack(ent) {
	player = ent.getPlayer();
	name = player.name;
	pos = [ent.getBlock().x, ent.getBlock().y, ent.getBlock().z];
	if (playObj[name]) {
		worldName = player.getLevel().getName();
		playObj[name].infoBlock = {
			world: worldName,
			pos: pos
		}
		if (playObj[name].addBlockClick) {
			playObj[name].addBlockClick = false;
			win = window.getCustomWindowBuilder('添加脚本方块'); //创建窗口
			win.buildInput('世界名', '方块在哪个世界', worldName);
			win.buildInput('X', '方块的X轴位置', pos[0]);
			win.buildInput('Y', '方块的Y轴位置', pos[1]);
			win.buildInput('Z', '方块的Z轴位置', pos[2]);
			win.buildDropdown('触发类型', '点击;摧毁;踩踏');
			win.buildToggle('是否阻止事件');
			win.buildInput('重置触发的初始时间', '时间格式：YYYY-MM-DD hh:mm:ss', timeData2YMD(new Date().getTime()));
			win.buildInput('重置触发次数时间(min)', '填写数字', 0);
			win.buildInput('触发延时(tick)', '填写数字', 0);
			win.buildInput('触发间隔(s)', '填写数字', 0);
			win.buildInput('每个玩家可触发次数', '填写数字', 0);
			win.buildToggle('是否提示失败信息(不包括条件不符合时的提示)', true);
			win.buildInput('条件不符合提示', '填写文本使用“;”分割', '金钱不大于100');
			win.buildInput('命令', '请输入命令文本', 'console@@%money%>100:sblock cmd tell %player% 金钱大于100&title %player% title 你好');
			win.showToPlayer(player, 'addBlockWinCallback'); //发送窗口
			return ent.setCancelled(true);
		}
		if (playObj[name].setBlockClick) {
			playObj[name].setBlockClick = false;
			if (blockData[worldName] === undefined) return player.sendMessage(lang.tips.non_existent_sblock);
			getblockData = blockData[worldName][pos.join("_")];
			if (getblockData === undefined) return player.sendMessage(lang.tips.non_sblock);
			win = window.getCustomWindowBuilder('设置脚本方块'); //创建窗口
			win.buildDropdown('触发类型', '点击;摧毁;踩踏');
			win.buildToggle('是否阻止事件', getblockData.isCancell);
			win.buildInput('重置触发的初始时间', '时间格式：YYYY-MM-DD hh:mm:ss', timeData2YMD(getblockData.ResetPlayerDataDelayTime));
			win.buildInput('重置触发次数时间(min)', '填写数字', getblockData.ResetPlayerDataDelay);
			win.buildInput('触发延时(tick)', '填写数字', getblockData.TriggerDelay);
			win.buildInput('触发间隔(s)', '填写数字', getblockData.TriggerInterval);
			win.buildInput('每个玩家可触发次数', '填写数字', getblockData.NumOfTrigger);
			win.buildToggle('是否提示失败信息(不包括条件不符合时的提示)', new Boolean(getblockData.isTips));
			win.buildInput('条件不符合提示', '填写文本使用“;”分割', getblockData.Tips);
			win.buildInput('命令', '请输入命令文本', getblockData.cmd);
			win.showToPlayer(player, 'setBlockWinCallback'); //发送窗口
			return ent.setCancelled(true);
		}
		if (playObj[name].moveBlockClick) {
			playObj[name].moveBlockClick = false;
			if (blockData[worldName] === undefined) return player.sendMessage(lang.tips.non_existent_sblock);
			playObj[name].fromInfoBlock = blockData[worldName][pos.join("_")];
			win = window.getCustomWindowBuilder('移动脚本方块'); //创建窗口
			win.buildInput('世界名', '移动至哪个世界', worldName);
			win.buildInput('X', '方块的X轴位置', pos[0]);
			win.buildInput('Y', '方块的Y轴位置', pos[1]);
			win.buildInput('Z', '方块的Z轴位置', pos[2]);
			win.showToPlayer(player, 'moveBlockWinCallback'); //发送窗口
			return ent.setCancelled(true);
		}
	}
	worldName = player.getLevel().getName();
	if (blockData[worldName] === undefined) return;
	pos = pos.join("_");
	getblockData = blockData[worldName][pos];
	if (!getblockData) return;
	if (getblockData.type != "点击") return; ent.setCancelled(getblockData.isCancell);
	if (getblockData.TriggerDelay != 0) return manager.setTimeout(function(getblockData, player, pos) {
		ScriptBlockCore(getblockData, player, pos)
	},
	getblockData.TriggerDelay, getblockData, player, pos);
	ScriptBlockCore(getblockData, player, pos);
}
function ScriptBlockPlayerMoveCallBack(ent) {
	player = ent.getPlayer();
	pos = [Math.floor(player.x), player.y - 1, Math.floor(player.z)].join("_");
	worldName = player.getLevel().getName();
	if(blockData[worldName] === undefined) return; getblockData = blockData[worldName][pos];
	if(!getblockData) return;
	if(getblockData.type != "踩踏") return; ent.setCancelled(getblockData.isCancell);
//	logger.info(['from:', ent.getFrom().x, ent.getFrom().y, ent.getFrom().z].join(' '));
//	logger.info(['to:', ent.getTo().x, ent.getTo().y, ent.getTo().z].join(' '));
	if (getblockData.TriggerDelay != 0) return manager.setTimeout(function(getblockData, player, pos) {
		ScriptBlockCore(getblockData, player, pos);
	},
	getblockData.TriggerDelay, getblockData, player, pos);
	ScriptBlockCore(getblockData, player, pos);

}
function ScriptBlockBlockBreakCallBack(ent) {
	player = ent.getPlayer();
	Block = ent.getBlock();
	pos = [Block.x, Block.y, Block.z].join("_");
	worldName = player.getLevel().getName();
	if (blockData[worldName] === undefined) return; getblockData = blockData[worldName][pos];
	if (!getblockData) return;
	if (getblockData.type != "摧毁") return; ent.setCancelled(getblockData.isCancell);
	if (getblockData.TriggerDelay != 0) return manager.setTimeout(function(getblockData, player, pos) {
		ScriptBlockCore(getblockData, player, pos);
	},
	getblockData.TriggerDelay, getblockData, player, pos);
	ScriptBlockCore(getblockData, player, pos);
	//blockitem.setBlock(Java.type("cn.nukkit.level.Position").fromObject(manager.buildvec3(Block.x, Block.y, Block.z), player.getLevel()), blockitem.buildBlock(Block.id, Block.getDamage()), true);
}

function ScriptBlockCore(getBlockConfig, player, pos) {
	name = player.name;
	if (player === null||server.getPlayer(name) === null) return logger.warning(lang.warn.non_online);
	uuid = server.getPlayer(name).getUniqueId().toString();
	if(getBlockConfig.ResetPlayerDataDelay > 0 && new Date().getTime() > getBlockConfig.ResetPlayerDataDelayTime) {
		getBlockConfig.PlayerData = {};
		while(new Date().getTime() > getBlockConfig.ResetPlayerDataDelayTime) {
			getBlockConfig.ResetPlayerDataDelayTime = getBlockConfig.ResetPlayerDataDelayTime + getBlockConfig.ResetPlayerDataDelay * 60 * 1000;
		}
	}
	PlayerObj = getBlockConfig.PlayerData[uuid] ? getBlockConfig.PlayerData[uuid] : {
		req: 0,
		timestamp: 0
	};// 获取玩家 执行次数&上次执行时间戳
	// 执行次数提示
	if(getBlockConfig.NumOfTrigger != 0) if(PlayerObj.req > getBlockConfig.NumOfTrigger - 1) if(getBlockConfig.isTips == 1){
		return player.sendMessage(lang.warn.num_trigger.replace("%1%", getBlockConfig.NumOfTrigger));
	} else {
		if(getBlockConfig.Tips != "") player.sendMessage(getBlockConfig.Tips);
		return;
	}
	// 执行延迟提示 - 开始
	timestamp = Math.floor(new Date().getTime() / 1000);
	PlayerExecTime = PlayerObj.timestamp + new Number(getBlockConfig.TriggerInterval);
	if(getBlockConfig.TriggerInterval != 0) if(PlayerExecTime > timestamp) if(getBlockConfig.isTips == 1) {
		return player.sendMessage(lang.warn.trigger_interval.replace("%1%", manager.time(PlayerExecTime - timestamp)));
	} else {
		if(getBlockConfig.Tips != "") player.sendMessage(getBlockConfig.Tips);
		return;
	}
	// 执行延迟提示 - 结束
	PlayerObj = {
		req: (PlayerObj.req + 1),
		timestamp: timestamp
	};// 更新玩家 执行次数&上次执行时间戳
	if(getBlockConfig.TriggerInterval === 0&&getBlockConfig.TriggerDelay === 0) {
		blockData[player.getLevel().getName()][pos].PlayerData = {};
	} else {
		blockData[player.getLevel().getName()][pos].PlayerData[uuid] = PlayerObj;
	}
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json", JSON.stringify(blockData));
	if (getBlockConfig.cmd) {
		cmdList = getBlockConfig.cmd.split(";");
		if (Config.variable.LevelAwakenSystem) {
			levelAwakenData = manager.readFile("./plugins/LevelAwakenSystem/Players/" + name.split('')[0].toLowerCase() + "/" + name + ".yml");
			if (levelAwakenData === "FILE NOT FOUND") {
				logger.warning(lang.err.expand_data.replace("%1%", "LevelAwakenSystem").replace("%2%", name));
				levelAwakenData = {};
			} else {
				levelAwakenData = JSON.parse(manager.YAMLtoJSON(levelAwakenData));
			}
		}
		if (Config.variable.Qwetitle) {
			QwetitleData = manager.readFile("./plugins/Qwetitle/Brassiere/" + name.toLowerCase() + ".yml");
			if (QwetitleData === "FILE NOT FOUND") {
				logger.warning(lang.err.expand_data.replace("%1%", "Qwetitle").replace("%2%", name));
				QwetitleData = {};
			} else {
				QwetitleData = JSON.parse(manager.YAMLtoJSON(QwetitleData));
			}
		}
		list:
		for (i = 0; i < cmdList.length; i++) {
			args = cmdList[i].split(/@@|:/g);
			if (args.length === 2) args = [args[0], 'true', args[1]];
			if (args.length != 3) return player.sendMessage(lang.err.sblock_cmd.replace("%1%", i+1));
			for (j = 1; j < 3; j++) {
				args[j] = args[j].replace(/%player%/ig, '"' + name + '"').replace(/%player_mode%/ig, manager.getPlayerGameMode(player)).replace(/%player_exp%/ig, player.getExperience()).replace(/%player_level%/ig, player.getExperienceLevel()).replace(/%player_x%/ig, player.x).replace(/%player_y%/ig, player.y).replace(/%player_z%/ig, player.z).replace(/%world%/ig, player.getLevel().getName()).replace(/%money%/ig, manager.getMoney(player));
				if (Config.variable.LevelAwakenSystem) args[j] = args[j].replace(/%level_level%/ig, levelAwakenData["等级"]).replace(/%level_exp%/ig, levelAwakenData["经验"]).replace(/%level_attri%/ig, levelAwakenData["属性"]).replace(/%level_health%/ig, levelAwakenData["生命"]).replace(/%level_jxs%/ig, levelAwakenData["觉醒次数"]).replace(/%level_talent%/ig, levelAwakenData["天赋"]);
				if (Config.variable.Qwetitle) args[j] = args[j].replace(/%Qwet_Sign%/ig, QwetitleData.Sign).replace(/%Qwet_Ban%/ig, QwetitleData.Ban);
			}
			if (!eval(args[1])) return player.sendMessage(getBlockConfig.Tips.split(";")[i] || lang.tips.non_compliant);
			args[2] = args[2].split('&');
			for (k = 0; k < args[2].length; k++) {
				if(args[2][k] == "return") break list;
				switch (args[0]) {
				case 'player':
					server.dispatchCommand(player, args[2][k]);
					break;
				case 'op':
					server.dispatchCommand(player, args[2][k]);
					break;
				case 'console':
					server.dispatchCommand(server.getConsoleSender(), args[2][k]);
					break;
				}
			}
		}
	}
}

function checkIsBear(name) {
	return server.getPlayer(name) != null ? new Boolean(manager.checkIsBear(server.getPlayer(name))) : false
};
function checkIsHaveItem(name, id, data, num) {
	return server.getPlayer(name) != null ? blockitem.hasItemToPlayer(server.getPlayer(name), blockitem.buildItem(id, data, num)) : false
};
function checkIsHaveTitle(name, title) {
	if(server.getPlayer(name) != null && Config.variable.Qwetitle){
		QwetitleCheckData = manager.readFile("./plugins/Qwetitle/Brassiere/" + name + ".yml");
		if (QwetitleCheckData === "FILE NOT FOUND") {
			logger.warning(lang.err.expand_data.replace("%1%", "Qwetitle").replace("%2%", name));
			QwetitleCheckData = {};
		} else {
			SignList = JSON.parse(manager.YAMLtoJSON(QwetitleCheckData)).Signs;
		}
		title = title.replace(/&.|§./g, '');
		for(t = 0; t<SignList.length; t++) {
			if(SignList[i].replace(/&.|§./g, '').indexOf(title) > -1) return true;
		}
	}
	return false;
}
function timeData2YMD(data){
	time = new Date(data);
	return time.toLocaleDateString()+' '+(time.getHours() < 10 ? "0"+time.getHours() : time.getHours())+':'+(time.getMinutes() < 10 ? "0"+time.getMinutes() : time.getMinutes())+':'+(time.getSeconds() < 10 ? "0"+time.getSeconds() : time.getSeconds());
}
// 初始化
if(manager.readFile('./plugins/BlocklyNukkit/ScriptBlock/Config.yml') === "FILE NOT FOUND") {
	manager.createConfig(manager.getFile("ScriptBlock", "blockData.json"), 2);
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/Config.yml", manager.JSONtoYAML(JSON.stringify({language:'chs', version:'2020-07-27', variable:{LevelAwakenSystem:true, Qwetitle: true}})));
}
if(manager.readFile('./plugins/BlocklyNukkit/ScriptBlock/lang/chs.yml') === "FILE NOT FOUND") {
	manager.writeFile("./plugins/BlocklyNukkit/ScriptBlock/lang/chs.yml", manager.JSONtoYAML(JSON.stringify({cmd:{
		sblock:'显示帮助',
		sblock_add: '添加脚本方块',
		sblock_set: '设置脚本方块',
		sblock_move: '移动脚本方块(指配置)',
		sblock_reload: '重载配置文件',
		sblock_exec: '让指定玩家触发指定位置的脚本方块',
		sblock_list: '列出所有或指定世界的脚本方块',
		sblock_delete: '删除指定位置的脚本方块',
		sblock_cmd_tell: '向指定玩家发送指定消息',
		sblock_cmd_tp: '传送指定玩家到某一位置',
		sblock_cmd_clear: '删除指定玩家一定数量的物品',
		sblock_cmd_setblock: '设置指定位置的方块',
		sblock_cmd_particle: '在指定位置绘制粒子效果'},
		tips:{
		non_cmd: '脚本方块 >>未知命令',
		non_existent_sblock: '脚本方块 >>该世界不存在脚本方块',
		non_sblock: '脚本方块 >>这不是一个脚本方块',
		non_compliant: '脚本方块 >>条件不符合',
		del_sblock: '脚本方块 >>已删除该脚本方块',
		new_set: '脚本方块 >>已保存新设置',
		start_click: '脚本方块 >>请点击一个实体方块',
		reload_done: '脚本方块 >>重新加载完成',
		move_suc: '脚本方块 >>移动成功脚本方块现位于：%1%'},
		warn:{
		non_online: '脚本方块 >>执行失败，玩家不在线',
		no_rights: '脚本方块 >>你无权进行此操作',
		is_console: '脚本方块 >>控制台无法进行此操作',
		trigger_interval: '§4你在 %1% 后才能再次触发！',
		num_trigger: '§4你只能触发 %1% 次！',
		move_faild: '脚本方块 >>移动失败，两次位置不得相同'},
		err:{
		arg: '脚本方块 >>命令参数错误',
		sblock_cmd: '脚本方块 >>该方块命令有误，在第 %1% 条',
		expand_data: '插件 %1% 不存在或没有玩家 %2% 的数据'}})));
}

manager.createConfig(manager.getFile("ScriptBlock", "blockData.json"), 2);
manager.createConfig(manager.getFile("ScriptBlock", "Config.yml"), 2);

var blockData = JSON.parse(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/blockData.json")),
Config = JSON.parse(manager.YAMLtoJSON(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/Config.yml"))),
lang = JSON.parse(manager.YAMLtoJSON(manager.readFile("./plugins/BlocklyNukkit/ScriptBlock/lang/"+Config.language+".yml"))),
playObj = {},
CommandList = [
	['sblock',lang.cmd.sblock],
	['sblock add', lang.cmd.sblock_add],
	['sblock set [<World: str> <Position: x y z> <ArgsName: str> <Value: str>]', lang.cmd.sblock_set],
	['sblock move', lang.cmd.sblock_move],
	['sblock reload', lang.cmd.sblock_reload],
	['sblock list [World: str]', lang.cmd.sblock_list],
	['sblock delete <World: str> <Position: x y z>', lang.cmd.sblock_delete],
	['sblock exec <Player> <World: str> <Position: x y z>', lang.cmd.sblock_exec],
	['sblock cmd tell <Player/@a> [Message: str]', lang.cmd.sblock_cmd_tell],
	['sblock cmd tp <Player/@a> <World: str> [Position: x y z]', lang.cmd.sblock_cmd_tp],
	['sblock cmd clear <Player/@a> <ID: int> <Data: int> <Quantity: int>', lang.cmd.sblock_cmd_clear],
	['sblock cmd particle <ID: int> <World: str> <Position: x y z>', lang.cmd.sblock_cmd_particle]
];
manager.createCommand(CommandList[0][0], CommandList[0][1], 'ScriptBlockhelp');
manager.bStats("ScriptBlock","2020-07-27","Mcayear",7986);
manager.setPrivateCall("RightClickBlockEvent", "ScriptBlockRTouchCallBack");
manager.setPrivateCall("PlayerMoveEvent", "ScriptBlockPlayerMoveCallBack");
manager.setPrivateCall("BlockBreakEvent", "ScriptBlockBlockBreakCallBack");